package com.zhoug.chart3.formatters;

import com.github.mikephil.charting.formatter.ValueFormatter;
import com.zhoug.chart3.utils.MPChartUtils;

/**
 * DataSetValueFormatter
 *
 * @Author 35574
 * @Date 2020/9/14
 * @Description
 */
public class MPDataSetValueFormatter extends ValueFormatter {
    private int decimalPlaces = 2;//小数位数
    private boolean fillEnd=false;//小数位不足是否需要补0
    private boolean isPercent=false;//是否是百分比
    /**
     * 值是否需要乘以100
     * eg: true 0.25 25% 坐标取值范围:0-1
     * eg: false 25  25%  坐标取值范围:0-100
     */
    private boolean multiply100 = false;

    public MPDataSetValueFormatter() {
    }


    public MPDataSetValueFormatter setMultiply100(boolean multiply100) {
        this.multiply100 = multiply100;
        return this;
    }

    public MPDataSetValueFormatter setFillEnd(boolean fillEnd) {
        this.fillEnd = fillEnd;
        return this;
    }

    public MPDataSetValueFormatter setPercent(boolean percent) {
        isPercent = percent;
        return this;
    }

    /**
     * 设置小数位数
     * @param decimalPlaces
     */
    public MPDataSetValueFormatter setDecimalPlaces(int decimalPlaces) {
        this.decimalPlaces = decimalPlaces;
        return this;
    }

    @Override
    public String getFormattedValue(float value) {
        if(isPercent){
            return MPChartUtils.formatDecimalUp(multiply100 ? value * 100 : value, decimalPlaces, fillEnd) + "%";
        }else{
            return MPChartUtils.formatDecimalUp(value,decimalPlaces,fillEnd);
        }
    }



}
